package cn.panda.edu.service.impl;

import cn.panda.edu.dao.TransactionMapper;
import cn.panda.edu.model.Transaction;
import cn.panda.edu.service.TransactionService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TransactionServiceImpl implements TransactionService {

	@Autowired
	TransactionMapper transactionMapper;
	@Override
	public int deleteByPrimaryKey(Integer transactionId) {
		// TODO Auto-generated method stub
		return transactionMapper.deleteByPrimaryKey(transactionId);
	}

	@Override
	public int insert(Transaction record) {
		// TODO Auto-generated method stub
		return transactionMapper.insert(record);
	}
	@Override
	public PageInfo<Transaction> listAll(int pageIndex, int pageSize, Integer studentId) {
		// TODO Auto-generated method stub
		Page<Transaction> page = PageHelper.startPage(pageIndex, pageSize);
		transactionMapper.listAllByStudentId(studentId);
		PageInfo<Transaction> pageInfo = new PageInfo<Transaction>(page);
		return pageInfo;
	}

	@Override
	public int insertTransaction(Transaction transaction) {
		// TODO Auto-generated method stub
		return transactionMapper.insertSelective(transaction);
	}
	
	@Override
	public int insertSelective(Transaction record) {
		// TODO Auto-generated method stub
		return transactionMapper.insertSelective(record);
	}

	@Override
	public Transaction selectByPrimaryKey(Integer transactionId) {
		// TODO Auto-generated method stub
		return transactionMapper.selectByPrimaryKey(transactionId);
	}

	@Override
	public int updateByPrimaryKeySelective(Transaction record) {
		// TODO Auto-generated method stub
		return transactionMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKeyWithBLOBs(Transaction record) {
		// TODO Auto-generated method stub
		return transactionMapper.updateByPrimaryKeyWithBLOBs(record);
	}

	@Override
	public int updateByPrimaryKey(Transaction record) {
		// TODO Auto-generated method stub
		return transactionMapper.updateByPrimaryKey(record);
	}

	@Override
	public PageInfo<Transaction> selectByPageAndSelective(Integer pageIndex, Integer pageSize) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pageIndex, pageSize);
		List<Transaction> tList = transactionMapper.selectByPageAndSelective(null);
		PageInfo<Transaction> pageInfo = new PageInfo<Transaction>(tList);
		return pageInfo;
	}
	@Override
	public PageInfo<Transaction> selectByPageAndSelective(Integer pageIndex, Integer pageSize,Integer studentId) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("studentId", studentId);
		PageHelper.startPage(pageIndex, pageSize);
		List<Transaction> tList = transactionMapper.selectByPageAndSelective(map);
		PageInfo<Transaction> pageInfo = new PageInfo<Transaction>(tList);
		return pageInfo;
	}


}
